/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufc.quixada.adrs.dao;

import br.ufc.quixada.adrs.dao.config.PostGresMapConfig;
import br.ufc.quixada.adrs.model.Municipio;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author franklin barroso
 */
public class MunicipioDAO {

    public void insert(Municipio municipio) throws SQLException{
        municipio.setId(proxId());
        PostGresMapConfig.getSqlMapClient().insert("addMunicipio",municipio);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    public void update(Municipio municipio) throws SQLException{
        PostGresMapConfig.getSqlMapClient().update("updateMunicipio",municipio);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    public void delete(Long id) throws SQLException{
        PostGresMapConfig.getSqlMapClient().queryForObject("deleteMunicipio", id);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    public List<Municipio> getByEstadoId(Long id) throws SQLException{
        return (List<Municipio>) PostGresMapConfig.getSqlMapClient().queryForList("getByEstadoId", id);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

     public List<Municipio> getAll() throws SQLException{
        return (List<Municipio>) PostGresMapConfig.getSqlMapClient().queryForList("getAll");
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    public List<Municipio> getByNome(String nome) throws SQLException{
        //nÃ£o entendo
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public Municipio getById(Long id) throws SQLException{
        return (Municipio) PostGresMapConfig.getSqlMapClient().queryForObject("getMunicipioById", id);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    private Long proxId() throws SQLException{
        Long id =(Long) PostGresMapConfig.getSqlMapClient().queryForObject("getMaxMunicipioId");
        if(id==null)
            id=0L;
        return id+1;
        //throw new UnsupportedOperationException("Not yet implemented");
    }

}
